package cn.ld.module.ai.dal.mapper.model;

import cn.ld.framework.common.pojo.PageResult;
import cn.ld.framework.mybatis.core.mapper.BaseMapperX;
import cn.ld.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.ld.framework.mybatis.core.query.QueryWrapperX;
import cn.ld.module.ai.controller.admin.model.vo.apikey.AiApiKeyPageInVO;
import cn.ld.module.ai.dal.entity.model.AiApiKeyEntity;
import org.apache.ibatis.annotations.Mapper;

/**
 * AI API 密钥 Mapper
 *
 * @author 蓝盾
 */
@Mapper
public interface AiApiKeyMapper extends BaseMapperX<AiApiKeyEntity> {

    default PageResult<AiApiKeyEntity> selectPage(AiApiKeyPageInVO inVO) {
        return selectPage(inVO, new LambdaQueryWrapperX<AiApiKeyEntity>()
                .likeIfPresent(AiApiKeyEntity::getName, inVO.getName())
                .eqIfPresent(AiApiKeyEntity::getPlatform, inVO.getPlatform())
                .eqIfPresent(AiApiKeyEntity::getStatus, inVO.getStatus())
                .orderByDesc(AiApiKeyEntity::getId));
    }

    default AiApiKeyEntity selectFirstByPlatformAndStatus(String platform, Integer status) {
        return selectOne(new QueryWrapperX<AiApiKeyEntity>()
                .eq("platform", platform)
                .eq("status", status)
                .limitN(1)
                .orderByAsc("id"));
    }

}